package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.MarketAd;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.admin.AdvertisementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author by yxy_8175@163.com
 * @Description TODO
 * @Date 2022-11-19 15:58
 */

@RestController
@RequestMapping("admin/ad")
public class AdvertisementController {

    @Autowired
    AdvertisementService advertisementService;

    /**
     * 查询当前页面的所有广告
     * @param  info 分页:page,limit  排序：sort,order
     * @return
     * @auto yxy_8175@163.com
     */
    @RequestMapping("list")
    public BaseRespVo listForAllAdvertisement(BasePageInfo info,String name,String content){

       CommonData<MarketAd> commonData = advertisementService.selectAllAds(info,name,content);

       return BaseRespVo.ok(commonData);
    }

    /**
     * 插入一条广告信息
     * @param ad
     * @return
     * @auto yxy_8175@163.com
     */
    @RequestMapping("create")
    public BaseRespVo createAd(@RequestBody MarketAd ad){

        MarketAd result = advertisementService.insetAd(ad);

        return BaseRespVo.ok(result);
    }

    /**
     * 更新广告信息
     * @return
     * @auto yxy_8175@163.com
     */
    @RequestMapping("update")
    public BaseRespVo updateAdInfo(@RequestBody MarketAd ad){

        MarketAd marketAd = advertisementService.updateAdInfo(ad);

        return BaseRespVo.ok(ad);

    }

    /**
     * 广告删除功能
     * @param ad
     * @return
     * @auto yxy_8175@163.com
     */
    @RequestMapping("delete")
    public BaseRespVo deleteAdInfo(MarketAd ad){
        int status = advertisementService.deleteAdInfo(ad);
        if (status == BaseRespVo.STATUS_OK){
            return BaseRespVo.ok();
        }
        return BaseRespVo.invalidData("删除失败...");
    }




}
